package cn.lixu.controller;

import cn.lixu.domain.Users;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ProjectName: springcloud-alibaba-parent-homework
 * @Package: cn.lixu.controller
 * @ClassName: UserController
 * @Author: LIXU
 * @Description: user调用接口
 * @Date: 2022/08/24 0024 22:50:17
 * @Version: 1.0
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("/getById/{id}")
    @SentinelResource(value = "user-server", blockHandler = "userFallback")
    public Users getById(@PathVariable("id") Long id) {
        return new Users(id, "罗顶天", "不男不女");
    }

    /**
     * @param null
     * @Method userFallback
     * @Author 小二黑
     * @Version 1.0
     * @Description 兜底数据
     * @Return
     * @Exception
     * @Date 2022/08/24 0024 23:48:58
     */
    public Users userFallback(@PathVariable("id") Long id, BlockException e) {
        e.printStackTrace();
        return new Users(-1L, "你点尼玛呢", "你是不是看不懂人话");
    }

}
